package com.ming.transaction.controller;


import com.ming.transaction.common.Result;
import com.ming.transaction.common.annotation.RecordLoggerAnnotation;
import com.ming.transaction.entity.Classify;
import com.ming.transaction.service.IClassifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 分类表 前端控制器
 * </p>
 *
 * @author 陈仕健
 * @since 2023-05-11
 */
@RestController
@RequestMapping("/classify")
@Api(tags = "分类控制器")
public class ClassifyController {

    @Resource
    private IClassifyService classifyService;

    /**
     * 查询所有分类
     * @return
     */
    @GetMapping
    @ApiOperation("查询所有类别")
    public Result findAllClassify(){
        return classifyService.findAll();
    }

    /**
     * 修改某个分类
     * @param classify
     * @return
     */
    @RecordLoggerAnnotation(value = "管理员修改分类")
    @PutMapping
    @ApiOperation("修改某个分类")
    public Result modifyClassify(@RequestBody Classify classify){
        return classifyService.updateClassify(classify);
    }

    /**
     * 删除某个分类
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除某个类别")
    public Result delClassify(@PathVariable("id") Integer id){
        return  classifyService.delClassify(id);
    }

    /**
     * 批量删除分类
     * @param ids
     * @return
     */
    @RecordLoggerAnnotation(value = "管理员批量删除分类")
    @PostMapping("/del/batch")
    @ApiOperation("批量删除分类")
    public Result delClassifys(@RequestBody List<Integer> ids){
        return classifyService.delClassifys(ids);
    }

    /**
     * 添加分类
     * @param classify
     * @return
     */
    @RecordLoggerAnnotation(value = "管理员添加分类")
    @ApiOperation("添加分类")
    @PostMapping
    public Result addClassify(@RequestBody Classify classify){
        return classifyService.addClasisfy(classify);
    }
}

